package com.atguigu.algorithm;

import java.util.ArrayList;
import java.util.Stack;

class ListNode{
    public int val;
    public ListNode next;
    public ListNode(int val){
        this.val=val;
    }
    public ListNode(){
    }
}
public class printListDesc {
    public ArrayList<Integer> printListFromTailToHead(ListNode head){
        if(head==null){
            return new ArrayList<>();
        }
        Stack<Integer> stack=new Stack<>();
        ListNode cur=head;
        while(cur!=null){
            stack.push(cur.val);
            cur=cur.next;
        }
        ArrayList<Integer> list=new ArrayList<>();
        while(!stack.isEmpty()){
            list.add(stack.pop());
        }
        return list;
    }
}
